﻿using Extend.Formatter;

/// <summary>
/// 只支持int float string
/// </summary>
public class StringFormatter
{
    static char[] _buf = new char[1024];

    public static string Write(string format)
    {
        var l = TextFormatter.Write(ref _buf, 0, format);
        return _Write(_buf, l);
    }

    public static string Format<T>(string format, T arg)
    {
        var l = TextFormatter.Write(ref _buf, 0, format, arg);
        return _Write(_buf, l);
    }

    public static string Format<T0, T1>(string format, T0 arg0, T1 arg1)
    {
        var l = TextFormatter.Write(ref _buf, 0, format, arg0, arg1);
        return _Write(_buf, l);
    }

    public static string Format<T0, T1, T2>(string format, T0 arg0, T1 arg1, T2 arg2)
    {
        var l = TextFormatter.Write(ref _buf, 0, format, arg0, arg1, arg2);
        return _Write(_buf, l);
    }

    public static string Format<T0, T1, T2, T3>(string format, T0 arg0, T1 arg1, T2 arg2, T3 arg3)
    {
        var l = TextFormatter.Write(ref _buf, 0, format, arg0, arg1, arg2, arg3);
        return _Write(_buf, l);
    }

    public static string Format<T0, T1, T2, T3, T4>(ref char[] dst, int destIdx, string format, T0 arg0, T1 arg1,
        T2 arg2, T3 arg3, T4 arg4)
    {
        var l = TextFormatter.Write(ref _buf, 0, format, arg0, arg1, arg2, arg3, arg4);
        return _Write(_buf, l);
    }

    public static string Format<T0, T1, T2, T3, T4, T5>(ref char[] dst, int destIdx, string format, T0 arg0, T1 arg1,
        T2 arg2, T3 arg3, T4 arg4, T5 arg5)
    {
        var l = TextFormatter.Write(ref _buf, 0, format, arg0, arg1, arg2, arg3, arg4, arg5);
        return _Write(_buf, l);
    }

    public static string _Write(char[] buf, int length)
    {
        return new string(buf, 0, length);
    }
}
